import org.apache.commons.lang.StringUtils;

public class Polygons {

    private static final String ASTERIKS = "*";

    public String asteriks() {
        return ASTERIKS;
    }

    public String horizontalLine(int size) {
        return StringUtils.repeat(ASTERIKS, size);
    }

    public String verticalLine(int size) {
        String line = "";
        for (int count = size; count > 0; count--) {
            line += ASTERIKS;
            if (count > 0) line += "\n";
        }
        return line;
    }

    public String rightTriangle(int size) {
        String triangle = "";
        int count = 1;
        while (count <= size) {
            triangle += horizontalLine(count) + "\n";
            count++;
        }
        return triangle;
    }

    public String centeredTriangle(int size) {
        String triangle = "";
        int totalColumnCount = 2 * size - 1;
        for (int count = 1; count <= size; count++) {
            int numSideSpaces = size - count;
            triangle += spaces(numSideSpaces);
            triangle += horizontalLine(totalColumnCount - numSideSpaces * 2);
            triangle += spaces(numSideSpaces);
            if (count > 0){
                triangle += "\n";
            }
        }
        return triangle;
    }

    public String spaces(int size) {
        return StringUtils.repeat(" ", size);
    }

    private String invertedCenteredTriangle(int size) {
        String triangle = " ";
        int totalColumnCount = 2 * size - 1;
        for (int count = size; count > 0; count--) {
            int halfSpace = size - count;
            triangle += spaces(halfSpace);
            triangle += horizontalLine(totalColumnCount - halfSpace * 2);
            triangle += spaces(halfSpace);
            triangle += "\n ";
        }
        return triangle;
    }

    public String centeredDiamond(int size) {
        return centeredTriangle(size) + invertedCenteredTriangle(size - 1);
    }

    private String centeredSpacedTriangle(int size) {
        String triangle = " ";
        int totalColumnCount = 2 * size - 1;
        for (int count = 1; count <= size; count++) {
            int halfSpace = size - count;
            triangle += spaces(halfSpace);
            triangle += horizontalLine(totalColumnCount - halfSpace * 2);
            triangle += spaces(halfSpace);
            triangle += "\n ";
        }
        return triangle;
    }

    public String diamondWithName(String name) {
        int size = name.length();
        return centeredSpacedTriangle(size - 1) + name + "\n" + invertedCenteredTriangle(size - 1);
    }

}
